#!/usr/bin/env python

# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Validation response produced by IDP and consumed by AP."""

from openidconnect.error import DataError

__author__ = 'Maciej Machulak'
__maintainer__ = 'Maciej Machulak'
__email__ = 'mmachulak@google.com'

__copyright__ = 'Copyright 2012, Google Inc.'
__license__ = 'Apache License 2.0'
__version__ = '0.2'
__status__ = 'Prototype'


class ValidationResponse(object):
  """Validation response produced by IDP and consumed by AP."""

  issuer = None
  audience = None
  scope = None
  client_id = None
  issued_at = None
  expires = None

  def __init__(self, response_dict):
    if not isinstance(response_dict, dict):
      raise DataError('invalid data format')
      # TODO(mmachulak) - no default values - raise DataError
    self.issuer = response_dict.get('issuer', None)
    self.audience = response_dict.get('audience', None)
    self.scope = response_dict.get('scope', None)
    self.client_id = response_dict.get('client_id', None)
    self.issued_at = response_dict.get('issued_at', None)
    self.expires = response_dict.get('expires', None)

  def __repr__(self):
    rsp = 'issuer: ' + (self.issuer or '')
    rsp += '\naudience: ' + (self.audience or '')
    rsp += '\nscope: ' + (self.scope or '')
    rsp += '\nclient_id: ' + (self.client_id or '')
    rsp += '\nissued_at: ' + (str(self.issued_at) or '')
    rsp += '\nexpires: ' + (str(self.expires) or '')
    return rsp
